home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 7.7 KB | 276 lines |
- /*
- * CellHints.java 1.0 12 Jan 1997
- *
- * Copyright (c) 1996 Krumel & Associates, Inc. All Rights Reserved.
- *
- * This software is provided as is. Krumel & Associates shall not be liable
- * for any damages suffered by licensee as a result of using, modifying or
- * distributing this software or its derivatives.
- */
-
- package symantec.itools.db.awt;
-
- import java.awt.*;
-
- public class CellHints {
- Rectangle bounds = new Rectangle();
- int align;
- int valign = Grid.TOP;
- boolean editable = true;
- boolean visible = true;
- Font font = stdFont;
- Color fg = Color.black;
- Color bg = Color.white;
- Color hfg = Color.white;
- Color hbg = Color.blue;
- boolean highlighted = false;
- boolean lineTop = true,
- lineBottom = true,
- lineLeft = true,
- lineRight = true;
- int lineTopStyle = Grid.THIN_LINE,
- lineBottomStyle = Grid.THIN_LINE,
- lineLeftStyle = Grid.THIN_LINE,
- lineRightStyle = Grid.THIN_LINE;
- Color lineTopColor = Color.gray,
- lineBottomColor = Color.gray,
- lineLeftColor = Color.gray,
- lineRightColor = Color.gray;
- int bits;
-
- public static final int ALIGN_BIT = 0;
- public static final int VALIGN_BIT = 1;
- public static final int EDITABLE_BIT = 2;
- public static final int VISIBLE_BIT = 3;
- public static final int FONT_BIT = 4;
- public static final int FG_BIT = 5;
- public static final int BG_BIT = 6;
- public static final int HFG_BIT = 7;
- public static final int HBG_BIT = 8;
-
- public static Font stdFont = new Font("Dialog", Font.PLAIN, 12);
- Grid view;
- TableCell cell;
-
- public CellHints(Grid v) {
- view = v;
- }
-
- public void set(int bit) {
- bits |= (1<<bit);
- }
-
- public void clear(int bit) {
- bits &= ~(1L << bit);
- }
-
- public boolean get(int bit) {
- return ((bits >> bit) & 1) != 0;
- }
-
- public void setForeground(Graphics g) {
- if (highlighted) {
- g.setColor(hfg);
- } else {
- g.setColor(fg);
- }
- }
-
- public void setBackground(Graphics g) {
- if (highlighted) {
- g.setColor(hbg);
- } else {
- g.setColor(bg);
- }
- }
-
- public void setHints(TableCell c) {
- cell = c;
-
- if (cell.type() == TableCell.CORNER_CELL) {
- setCornerCellHints(c);
- return;
- } else if (cell.type() == TableCell.ROW_HEADING) {
- //Is this ever the case
- } else if (cell.type() == TableCell.COL_HEADING) {
- //Need to implement this
- }
-
- bounds = view.getCellBounds(c, bounds);
- align = view.getCellAlignment(c);
- fg = view.getCellFG(c);
- bg = view.getCellBG(c);
- editable = view.getCellEditable(c);
- highlighted = view.getCellHighlighted(c);
- font = view.getCellFont(c);
- }
-
- void setCornerCellHints(TableCell c) {
- CellHints rowHints = view.rowHeadingHints;
-
- bounds = view.getCellBounds(c, bounds);
- align = rowHints.align;
- fg = rowHints.fg;
- bg = rowHints.bg;
- editable = rowHints.editable;
- highlighted = view.isViewSelected();
- font = rowHints.font;
- }
-
- public void drawBoundary(Graphics g) {
- Rectangle r = bounds;
- if (lineTop) {
- g.setColor(lineTopColor);
- g.drawLine(r.x, r.y, r.x+r.width-1, r.y);
- }
- if (lineBottom) {
- g.setColor(lineBottomColor);
- g.drawLine(r.x, r.y+r.height-1, r.x+r.width-1, r.y+r.height-1);
- }
- if (lineLeft) {
- g.setColor(lineLeftColor);
- g.drawLine(r.x, r.y, r.x, r.y+r.height-1);
- }
- if (lineRight) {
- g.setColor(lineRightColor);
- g.drawLine(r.x+r.width-1, r.y, r.x+r.width-1, r.y+r.height-1);
- }
- }
-
- public boolean isVisible() { return visible; }
-
- public boolean cascadeIsVisible(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(VISIBLE_BIT)) {
- return c2.visible;
- } else if (c1 != null && c1.get(VISIBLE_BIT)) {
- return c1.visible;
- }
-
- return visible;
- }
-
- public Rectangle bounds() { return bounds; }
-
- public int alignment() { return align; }
-
- public int cascadeAlignment(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(ALIGN_BIT)) {
- return c2.align;
- } else if (c1 != null && c1.get(ALIGN_BIT)) {
- return c1.align;
- }
-
- return align;
- }
-
- public boolean editable() { return editable; }
-
- public boolean cascadeEditable(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(EDITABLE_BIT)) {
- return c2.editable;
- } else if (c1 != null && c1.get(EDITABLE_BIT)) {
- return c1.editable;
- }
-
- return editable;
- }
-
- public int vAlignment() { return valign; }
-
- public int cascadeVAlignment(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(VALIGN_BIT)) {
- return c2.valign;
- } else if (c1 != null && c1.get(VALIGN_BIT)) {
- return c1.valign;
- }
-
- return valign;
- }
-
- public Font font() { return font; }
-
- public Font cascadeFont(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(FONT_BIT)) {
- return c2.font;
- } else if (c1 != null && c1.get(FONT_BIT)) {
- return c1.font;
- }
-
- return font;
- }
-
- public Color foreground() { return fg; }
-
- public Color cascadeForeground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(FG_BIT)) {
- return c2.fg;
- } else if (c1 != null && c1.get(FG_BIT)) {
- return c1.fg;
- }
-
- return fg;
- }
-
- public Color background() { return bg; }
-
- public Color cascadeBackground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(BG_BIT)) {
- return c2.bg;
- } else if (c1 != null && c1.get(BG_BIT)) {
- return c1.bg;
- }
-
- return bg;
- }
-
- public boolean highlighted() { return highlighted; }
-
- public Color hlForeground() { return hfg; }
-
- public Color cascadeHlForeground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(HFG_BIT)) {
- return c2.hfg;
- } else if (c1 != null && c1.get(HFG_BIT)) {
- return c1.hfg;
- }
-
- return hfg;
- }
-
- public Color hlBackground() { return hbg; }
-
- public Color cascadeHlBackground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(HBG_BIT)) {
- return c2.hbg;
- } else if (c1 != null && c1.get(HBG_BIT)) {
- return c1.hbg;
- }
-
- return hbg;
- }
-
- public boolean lineTop() { return lineTop; }
-
- public boolean lineBottom() { return lineBottom; }
-
- public boolean lineLeft() { return lineLeft; }
-
- public boolean lineRight() { return lineRight; }
-
- public Color lineTopColor() { return lineTopColor; }
-
- public Color lineBottomColor() { return lineBottomColor; }
-
- public Color lineLeftColor() { return lineLeftColor; }
-
- public Color lineRightColor() { return lineRightColor; }
-
- public int lineTopStyle() { return lineTopStyle; }
-
- public int lineBottomStyle() { return lineBottomStyle; }
-
- public int lineLeftStyle() { return lineLeftStyle; }
-
- public int lineRightStyle() { return lineRightStyle; }
- }
-